<?php
	$hfbcats 	= getHFBCats();
	$borders 	= getBorders();
	$buttons	= getButtonsList();
	$iconsets	= getIconSetList();
	
	if($_REQUEST['item'] > 0)
	{ $item['id'] = $_REQUEST['item']; }
	if($item['id'] > 0)
	{ 
		$item 			= getBorderAdmin($item['id']); 
		$incats 		= getInHFBCats($item['id'], 6);
	}
	
	switch ($_POST['action'])
	{
		case 'new_item':
			if($_POST['name'] != '')
			{ addBorder($_POST['name']); }
			$i=0;
			if($_POST['brd_id'])
			{
				foreach($_POST['brd_id'] as $id)
				{
					updateBorder($id, $_POST['brd_name'][$i], $_POST['brd_type'][$i], $_POST['brd_width'][$i]);
					$i++;
				}
			}
			if($_POST['load_css'] > 0)
			{ reloadHFBTypeCss($_POST['load_css']); }
			if($_POST['activate'] > 0)
			{ setTableActive($_POST['activate'], 'com_borders', 1); }
			if($_POST['deactivate'] > 0)
			{ setTableActive($_POST['deactivate'], 'com_borders', 0); }
			if($_POST['delete_border'] > 0)
			{ deleteBorder($_POST['delete_border']); } 
			break;
		case 'editor':
			if($item['id'] > 0)
			{
				$error = updateBorder($item['id'], $_POST['name'], $_POST['type'], $_POST['width']);
				$error = uploadBorderImages($item['id']);
				
				if($_POST['add_to_cat'] > 0)
				{ addItemToCat($item['id'], 6, $_POST['add_to_cat']);}
				if($_POST['rem_from_cat'] > 0)
				{ removeItemFromCat($item['id'], 6, $_POST['rem_from_cat']);}
				
				if($_POST['delete_image_bg'] == 1)
				{ deleteBorderImage($item['id'], 'image_bg', $item['image_bg']);  }
				
				if($_POST['delete_image_top'] == 1)
				{ deleteBorderImage($item['id'], 'image_top', $item['image_top']);  }
				if($_POST['delete_image_top_l'] == 1)
				{ deleteBorderImage($item['id'], 'image_top_l', $item['image_top_l']);  }
				if($_POST['delete_image_top_r'] == 1)
				{ deleteBorderImage($item['id'], 'image_top_r', $item['image_top_r']);  }
				
				if($_POST['delete_image_bot'] == 1)
				{ deleteBorderImage($item['id'], 'image_bot', $item['image_bot']);  }
				if($_POST['delete_image_bot_l'] == 1)
				{ deleteBorderImage($item['id'], 'image_bot_l', $item['image_bot_l']);  }
				if($_POST['delete_image_bot_r'] == 1)
				{ deleteBorderImage($item['id'], 'image_bot_r', $item['image_bot_r']);  }
				
				if($_POST['delete_image_mid_l'] == 1)
				{ deleteBorderImage($item['id'], 'image_mid_l', $item['image_mid_l']);  }
				if($_POST['delete_image_mid_r'] == 1)
				{ deleteBorderImage($item['id'], 'image_mid_r', $item['image_mid_r']);  }
				
				updateCss(6,$item['id'],'div.rc_border div.border_'.$item['id'].'', $_POST['border']);
				
				updateCss(6,$item['id'],'div.rc_border div.border_'.$item['id'].' div.top_'.$item['id'], $_POST['top']);
				updateCss(6,$item['id'],'div.rc_border div.border_'.$item['id'].' div.tl_'.$item['id'], $_POST['tl']);
				updateCss(6,$item['id'],'div.rc_border div.border_'.$item['id'].' div.tr_'.$item['id'], $_POST['tr']);
				
				updateCss(6,$item['id'],'div.rc_border div.border_'.$item['id'].' div.bot_'.$item['id'], $_POST['bot']);
				updateCss(6,$item['id'],'div.rc_border div.border_'.$item['id'].' div.bl_'.$item['id'], $_POST['bl']);
				updateCss(6,$item['id'],'div.rc_border div.border_'.$item['id'].' div.br_'.$item['id'], $_POST['br']);
				
				updateCss(6,$item['id'],'div.rc_border div.border_'.$item['id'].' div.core_'.$item['id'], $_POST['core']);
				updateCss(6,$item['id'],'div.rc_border div.border_'.$item['id'].' div.mid_l_'.$item['id'], $_POST['mid_l']);
				updateCss(6,$item['id'],'div.rc_border div.border_'.$item['id'].' div.mid_r_'.$item['id'], $_POST['mid_r']);
				reloadHFBTypeCss(6);
			}
			break;
	}
	if($_REQUEST['cat'] > 0)
	{ $borders = getBorders($_REQUEST['cat']); }
	else
	{ $borders = getBorders(); }
	if($item['id'] > 0)
	{ 
		$item = getBorderAdmin($item['id']); 
		$incats = getInHFBCats($item['id'], 6);
	}
?>